<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
        <title>2. Usage</title>
        <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" title="Ref" charset="utf-8"/>
    </head>
    <body class="body">
    <h1><a name="2. Usage">2. Usage</a></h1>The plugin will try to expose all the TagLib artefacts, registered at grailsApplication.tagLibsClasses, as user-defined directives and functions (for implementation details, please refer to <a href="http://freemarker.sourceforge.net/docs/app_faq.html#faq_implement_function_or_macro_in_java" target="blank">FreeMarker FAQ</a> ). These directives and functions will be defined at runtime and exposed as shared variables, using the same namespace of the source taglibs, in any FreeMarker template created further.<p class="paragraph"/><blockquote class="warning">
Be aware that some templates can mistakenly/inadvertently "shadow" shared variables definitions.
</blockquote><h2><a name="2.1. Syntax tips (GSP vs. FTL)">2.1. Syntax tips (GSP vs. FTL)</a></h2>The following items contain useful information about some of the differences between Grails Server Pages (.gsp) and FreeMarker Templates (.ftl). Please note this is not intended to be a complete list, it's just a starting point for begginers.<p class="paragraph"/><h2><a name="2.1.1. Maps vs. Hashes">2.1.1. Maps vs. Hashes</a></h2>.gsp<p class="paragraph"/><div class="code"><pre>&#91;key1: 'abc', key2: 2&#93;</pre></div><p class="paragraph"/>
.ftl<p class="paragraph"/><div class="code"><pre>&#123;'key1': 'abc', 'key2': 2&#125;</pre></div><p class="paragraph"/><h2><a name="2.1.2. Tags vs. Tags">2.1.2. Tags vs. Tags</a></h2>.gsp<p class="paragraph"/><div class="code"><pre>&#60;g:includeJs script=<span class="java&#45;quote">"myscript"</span> /&#62;</pre></div><p class="paragraph"/>
.ftl<p class="paragraph"/><div class="code"><pre>&#60;@g.includeJs script=<span class="java&#45;quote">"myscript"</span> /&#62;</pre></div><p class="paragraph"/>or<p class="paragraph"/><div class="code"><pre>&#91;@g.includeJs script=<span class="java&#45;quote">"myscript"</span> /&#93;</pre></div><p class="paragraph"/>
Parameter values are (arbitrary complex) expressions that are not quoted. So assuming you want to pass an integer to foo, &#60;&#64;foo bar=1 /&#62; is good, but &#60;&#64;foo bar="1" /&#62; is wrong as it passes in the value as a string (because "1" is a string literal, just like in Groovy). For the same reason, &#60;&#64;foo bar=x+1 /&#62; is good, but &#60;&#64;foo bar="${x+1}" /&#62; does something else.<p class="paragraph"/><h2><a name="2.1.3. Tags as method calls vs. Method calls">2.1.3. Tags as method calls vs. Method calls</a></h2>.gsp<p class="paragraph"/><div class="code"><pre>&#60;span id=<span class="java&#45;quote">"title"</span> class=<span class="java&#45;quote">"label $&#123;hasErrors(bean:book,field:'title','errors')&#125;"</span>&#62;Title&#60;/span&#62;</pre></div><p class="paragraph"/>
.ftl<p class="paragraph"/><div class="code"><pre>&#60;span id=<span class="java&#45;quote">"title"</span> class=<span class="java&#45;quote">"label $&#123;g.hasErrors(&#123;'bean':book,'field':'title'&#125;,'errors')&#125;"</span>&#62;Title&#60;/span&#62;</pre></div><p class="paragraph"/>
<blockquote class="note">
The plugin will define functions using the same namespace of the corresponding directives.
All functions will receive two parameters, at most: a hash and an evaluated string. 
</blockquote>

    </body>
</html>
